
import httplib
import json
from source.confs.constants import Config


class CountAlarms:
    def getCurAlarm(self, resource_id):
        count = -1
        httpClient = httplib.HTTPConnection(Config.OpenO_URL, Config.OpenO_Port, Config.Request_Timeout)
        headers = {"Content-type": "application/json"}
        reqUrl = Config.GetCurAlarms_Rest_URL + '?oid=' + resource_id

        try:
            httpClient.request("GET", reqUrl, headers=headers)
            response = httpClient.getresponse()
            if response.status == 200:
                body = json.loads(response.read())
                count = body
        except Exception, e:
            print e
        if httpClient:
            httpClient.close()

        meter = {}
        meter['alarm_nums'] = str(count)
        return meter